package com.pda.gongpin.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import com.pda.gongpin.R;
import com.pda.gongpin.bean.FullTrayInDetailBean;
import com.pda.gongpin.dialog.AffirmDialog;
import com.pda.gongpin.presenter.FullTrayInDetailPresenter;
import com.pda.gongpin.view.SlideRecyclerView;
import com.wangshen.base.ui.mvp.base.adapter.BaseAdapter;

import java.util.List;

public class FullTrayInDetailAdapter extends BaseAdapter<FullTrayInDetailBean> {
    FullTrayInDetailPresenter presenter;

    public FullTrayInDetailPresenter getPresenter() {
        return presenter;
    }

    public void setPresenter(FullTrayInDetailPresenter presenter) {
        this.presenter = presenter;
    }

    public FullTrayInDetailAdapter(int layoutResId, @Nullable List<FullTrayInDetailBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, FullTrayInDetailBean item) {
        super.convert(helper, item);
        helper.setText(R.id.tv_sku,item.getTitle());
        helper.setText(R.id.tv_materialCode,"我的料号: "+item.getMaterial());
        helper.setText(R.id.tv_articleId,"物资编号："+item.getArticleId());
        helper.setText(R.id.tv_articleName,"物资名称："+item.getArticleName());
        helper.setText(R.id.tv_surfaceTreatment,"表色："+item.getSurfaceTreatment());
        helper.setText(R.id.tv_brand,"品牌："+item.getBrand());
        helper.setText(R.id.tv_packageSpecFull,"包规："+item.getPackageSpecFull());
        helper.setText(R.id.tv_shouldNumStr,"应上架："+item.getShouldNumStr());
        helper.setText(R.id.tv_alreadyNumStr,"已上架："+item.getAlreadyNumStr());
        helper.setText(R.id.tv_spec,"规格："+item.getSpec()+"");
        helper.setText(R.id.tv_standard,"标准："+item.getStandard());
        helper.setText(R.id.tv_grade,"等级："+item.getGrade());
        RecyclerView recyclerView=helper.getView(R.id.rv_list);
        CheckBox checkBox=helper.getView(R.id.cb_original);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    checkBox.setText("展开");
                    recyclerView.setVisibility(View.GONE);
                }else {
                    checkBox.setText("关闭");
                    recyclerView.setVisibility(View.VISIBLE);
                }
            }
        });
        FullTrayInDetailListAdapter adapter=new FullTrayInDetailListAdapter(R.layout.item_full_in_detail_list,item.getList());
        recyclerView.setAdapter(adapter);
        adapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter adapter1, @NonNull View view, int position) {
                if (view.getId() == R.id.tv_state){
                    if (adapter.getData().get(position).getCarryStatus().equals("10")){
                        AffirmDialog dialog=new AffirmDialog(getContext(), new AffirmDialog.OnConfrim() {
                            @Override
                            public void onConfrim() {
                                presenter.deleteEntryNotAvailable(adapter.getData().get(position).getEntryDetailNo());
                            }
                        });
                       dialog.show("确定要删除吗？");
                    }else {
                        AffirmDialog dialog=new AffirmDialog(getContext(), new AffirmDialog.OnConfrim() {
                            @Override
                            public void onConfrim() {
                                presenter.entryTakenOffShelves(adapter.getData().get(position).getEntryDetailNo());
                            }
                        });
                        dialog.show("确定要下架吗？");

                    }
                }
            }
        });
    }
}
